const funds='002451,003231,005044,007610,005918,007776,100032,002316,007874,002291'; // 请设置基金代码，用英文


let widget=await createWidget()
Script.setWidget(widget)
Script.complete()

async function createWidget() {
  
  
     
 let w= new ListWidget()
 w.backgroundColor=new Color('#111',0.9);

    let date=w.addText("基金实况");
    date.font=Font.boldSystemFont(17);
    date.textColor=Color.white();
    w.addSpacer(8)
    
    
    try {
  const l=config.widgetFamily=='large'?10:10;
  const reqF=new Request('https://api.doctorxiong.club/v1/fund?code='+funds), resF=await reqF.loadJSON()||{};
  let F=resF.data||[];
  if (F.length>l) {F.length=l;}
  for (let o of F) {
   w.addSpacer(11);
   let fund=w.addText(o.name+' · '+o.expectWorth+' ('+(o.expectGrowth>0?'+':'')+o.expectGrowth+'%)');
   fund.font=Font.lightSystemFont(12);
            if (o.expectGrowth > 0)
    fund.textColor=new Color('#dc143c',0.9);  //显示红色
   else if(0 == o.expectGrowth)
    fund.textColor=new Color('#778899',0.9);  //灰色
   else
    fund.textColor=new Color('#3cb371',0.9);  //绿色


   //fund.textColor=new Color('#b3e5fc',0.9);
   fund.textOpacity=0.8;
  }
 } catch (err) {
  let fund=w.addText('暂时与证券交易所失去了联系');
  fund.font=Font.lightSystemFont(11);
  fund.textColor=new Color('#b3e5fc',0.9);
  fund.textOpacity=0.8;
 }
 return w;
}